﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using  SmartMathLibrary.Lua;

namespace QuickTest
{
    public class LuaTestClass
    {
        private  lua51 lua;

        public LuaTestClass()
        {
            lua = new lua51();
            lua.ConnectDotNet(Log, lua);
            lua.RegisterFunction("testfunc", examplefunction);
            lua.RegisterFunction("testfunc2", examplefunction2);
        }

        public int examplefunction()
        {
            string p1 = lua.GetParameterString(1);
            Console.WriteLine("Hello from Lua: " + p1);
            return 0;
        }
        public int examplefunction2()
        {
            double n = lua.GetParameterNumber(1);
            lua.ReturnDouble(n * 2);
            return 1;
        }

        public void Log(string Txt)
        {
            Console.WriteLine(Txt);
           

        }

        public void DO()
        {
            //lua.DoString("i = 0\r\nd = 0\r\nrepeat\r\n  i = i + 1\r\n  d =d + testfunc2(i)\r\n  print(i)\r\nuntil i == " +
            //    "10\r\ntestfunc(tostring(d))\r\n");

            lua.DoString("a = {1, 4, 9, 16, 25, 36, 49, 64, 81}\nfor i=1, 9 do\nprint(a[i])\nend");
        }
    }
}
